package com.example.voucher.contract.spi;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import com.example.voucher.contract.VoucherItemCapable;
import com.example.voucher.entity.Company;
import com.example.voucher.entity.SalesInvoice;
import com.example.voucher.entity.SalesInvoiceSn;
import com.example.voucher.enums.VoucherScenarioEnum;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public class VoucherItemCapableSalesInvoiceAdapter implements VoucherItemCapable {
    private SalesInvoice invoice;
    private SalesInvoiceSn invoiceSn;
    private Company company;

    @Override
    public String getOrgTitleCode() {
        return company.getOrgTitleCode();
    }

    @Override
    public String getOrgTitleName() {
        return company.getOrgTitle();
    }

    @Override
    public String getOrgTitleFullname() {
        return company.getOrgFullTitle();
    }

    @Override
    public String getOppoOrgTitleCode() {
        return invoice.getCustomerCode();
    }

    @Override
    public String getOppoOrgTitleName() {
        return invoice.getOppoOrgTitleName();
    }

    @Override
    public String getOppoOrgTitleFullname() {
        return invoice.getOppoOrgTitleName();
    }

    @Override
    public String getInvoiceCode() {
        return invoice.getPrintno();
    }

    @Override
    public String getInvoiceNo() {
        return invoice.getPrintInvoiceCode();
    }

    @Override
    public Date getInvoiceDate() {
        return invoice.getPrintorTime();
    }

    @Override
    public Long getInvoiceId() {
        return invoice.getPkid();
    }

    @Override
    public Integer getInvoiceSn() {
        return invoiceSn.getPkid().intValue(); // TODO
    }

    @Override
    public Long getInvoiceSnId() {
        return invoiceSn.getPkid();
    }

    @Override
    public BigDecimal getWeight() {
        return invoiceSn.getWeight();
    }

    @Override
    public BigDecimal getPreTaxAmount() {
        return invoiceSn.getNoTaxAmt();
    }

    @Override
    public BigDecimal getTaxAmount() {
        return invoiceSn.getTaxLimit();
    }

    @Override
    public BigDecimal getPriceTaxAmount() {
        return invoiceSn.getWithTaxAmt();
    }

    @Override
    public String getOrderCode() {
        String orderCode = "";
        if (StringUtils.isNotBlank(invoiceSn.getExternalNo())) {
            orderCode = invoiceSn.getExternalNo();
        } else {
            orderCode = invoiceSn.getOrderCode();
        }
        return orderCode;
    }

    @Override
    public Date getOrderDate() {
        return invoice.getPrintorTime(); // TODO
    }

    @Override
    public String getRcCode() {
        return invoice.getRcCode();
    }

    @Override
    public String getRcName() {
        return invoice.getRcName();
    }

    @Override
    public String getProductLine() {
        return invoiceSn.getProductLine();
    }

    @Override
    public String getScenario() {
        return VoucherScenarioEnum.SaleInvoice.getCode();
    }

    @Override
    public String getSiteCode() {
        return invoiceSn.getSiteCode();
    }

    @Override
    public String getSiteName() {
        return invoiceSn.getSiteName();
    }

    @Override
    public String getSiteFullname() {
        return invoiceSn.getSiteFullname();
    }

    @Override
    public Date getScanDate() {
        return invoice.getPrintorTime();
    }

    @Override
    public String getUnit() {
        return invoiceSn.getUnit();
    }

    @Override
    public String getQtyUnit() {
        return invoiceSn.getWeight().stripTrailingZeros().toPlainString() + invoiceSn.getUnit();
    }

    @Override
    public String getItName() {
        return invoiceSn.getCategory();
    }

}
